package cn.iocoder.yudao.module.erp.dal.mysql.purchaseplan.purchaseservicedetail;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.purchaseplan.vo.purchaseservicedetail.PurchaseServiceDetailPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchaseplan.purchaseservicedetail.PurchaseServiceDetailDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 服务采购详情 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PurchaseServiceDetailMapper extends BaseMapperX<PurchaseServiceDetailDO> {

    default PageResult<PurchaseServiceDetailDO> selectPage(PurchaseServiceDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PurchaseServiceDetailDO>()
                .eqIfPresent(PurchaseServiceDetailDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(PurchaseServiceDetailDO::getPurchaseType, reqVO.getPurchaseType())
                .eqIfPresent(PurchaseServiceDetailDO::getPurchaseContent, reqVO.getPurchaseContent())
                .eqIfPresent(PurchaseServiceDetailDO::getServicePeriod, reqVO.getServicePeriod())
                .eqIfPresent(PurchaseServiceDetailDO::getServiceLocation, reqVO.getServiceLocation())
                .eqIfPresent(PurchaseServiceDetailDO::getSupplierQualification, reqVO.getSupplierQualification())
                .eqIfPresent(PurchaseServiceDetailDO::getTechnicalReview, reqVO.getTechnicalReview())
                .eqIfPresent(PurchaseServiceDetailDO::getCurrentInventory, reqVO.getCurrentInventory())
                .eqIfPresent(PurchaseServiceDetailDO::getUnit, reqVO.getUnit())
                .eqIfPresent(PurchaseServiceDetailDO::getEstimatedQuantity, reqVO.getEstimatedQuantity())
                .eqIfPresent(PurchaseServiceDetailDO::getEstimatedUnitPrice, reqVO.getEstimatedUnitPrice())
                  .eqIfPresent(PurchaseServiceDetailDO::getTotalAmount, reqVO.getTotalAmount())
                .eqIfPresent(PurchaseServiceDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(PurchaseServiceDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PurchaseServiceDetailDO::getId));
    }

    default void deleteByPlanId(Long planId){
        LambdaUpdateWrapper<PurchaseServiceDetailDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(PurchaseServiceDetailDO::getPlanId, planId);
        this.delete(updateWrapper);
    }

    default List<PurchaseServiceDetailDO> selectByPlanId(Long planId){
        LambdaQueryWrapper<PurchaseServiceDetailDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PurchaseServiceDetailDO::getPlanId, planId)
                .eq(PurchaseServiceDetailDO::getDeleted,0);
        return this.selectList(queryWrapper);
    }
}